<style>
    a:link {color:#FFFFFF;}    /* unvisited link */
    a:visited {color:#FFFFFF;} /* visited link */
    a:hover {color:#FFFFFF;}   /* mouse over link */
    a:active {color:#FFFFFF;}  /* selected link */
</style>
<?php
include dirname(__FILE__) . "/config/functions.php";

$id = $_GET['id'];
if (isset($_SESSION['code_' . $id]) && isset($_SESSION['url_' . $id])) {
    $code = $_SESSION['code_' . $id];
    $url = $_SESSION['url_' . $id];
    $urlId = $_SESSION['url_id_' . $id];

    // sponser link
    if ($id == 0) {
        $urlRecord = mysql_query("SELECT * from ads WHERE id='" . $urlId . "'");
        $urlRecord = mysql_fetch_array($urlRecord);
        $qry = "UPDATE `ads` SET `updated_at`= now(), `current` = '" . ($urlRecord['current'] + 1) . "' WHERE `id` ='" . $urlId . "'";
        mysql_query($qry);
    }
} else {
    header('location: index.php');
}
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>
<body style="background-image: url('images/008.jpg');background-repeat: repeat-x;background-color: #D3D3D3;margin: 0px">

    <div id="image" style="font-size: 12px; float: left;"> 
        <img src="images/default_logo.png" />
    </div>

    <div id="banner" style="width: 475px; float: right; font-size: 12px; margin: 7px;"> 
		<?php $_borders=false ?>
		<?php include_once dirname(__FILE__) . '/_banner.php'; ?>
    </div>

    <div id="code" style="font-weight: bold; font-size: 15px; text-align: center; overflow: hidden; padding-top: 15px;color: #FFFFFF;"> 
        Please wait while generating Ad code ... <span id="timer"> 15</span> Sec.
    </div>

    <iframe scrolling="auto" src="<?= $url ?>" style="width:100%;height:100%;border:0;" id="iframe"></iframe>

    <div id="cd" style="display: none;">
        <?= ($id) ? addOrdinalNumberSuffix($id) : ''; ?> Ad Code is <input type="text" id="tc" size="9" value="<?= $code ?>">
        copy/paste code on main page
        <br><a href="<?= $url ?>" target="_parent" style="font-weight: normal;">Remove Top Frame</a>
    </div>
</body>
<script>
    $(document).ready(function(){
        setTimeout(function(){	$('#code').html($('#cd').html());        }, 16000);
        setInterval(function(){	$('#timer').html(parseInt($('#timer').html())-1);        }, 1000);
    });
</script>